package com.golf.core.course.bodies;

import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.Circle;

/**
 * NB: Nopt thread safe !!
 * 
 * @author gfloodgate
 */
public class Ball extends AbstractCourseBody implements MovableCourseBody 
{
    
    /** The default ball radius. */
    private static final float DEFAULT_REDIUS = 6.0f;
	
    /** The balls radius. */
    private final float radius;

    /** the current position of the ball. */
	private Position position;
	
	/** The current direction and speed of the ball (initially nothing). */
	private Vector vector = Vector.STATIONARY;
	

	/**
	 * Create a ball that can be used in the game.
	 * 
	 * @param name The unique name of the ball.
	 * @param position The starting position of the ball.
	 */
	public Ball(final String name, final Position position)
	{
		super(name);
		
	    this.position = position;
	    this.radius = DEFAULT_REDIUS;
	}
	
	
	/**
	 * {@inheritDoc}
	 */
    public Body asPhysicsBody()
    {
        Body body = new Body(name(), new Circle(radius), 100.5f);
        body.setPosition(position.getX() + radius, position.getY() + radius);
        body.setRestitution(0.4f);
        body.setRotDamping(0.4f);
        body.setFriction(1f);
    
        return body;
    }


    /**
     * {@inheritDoc}
     */
    public void setPosition(final Position position)
    {
        this.position = position;
    }

    
    /**
     * {@inheritDoc}
     */
    public void setPosition(final float x, final float y)
    {
        position = new Position(x, y);
    }
    
    
    /**
     * {@inheritDoc}
     */
    public Position getPosition()
    {
        return position;
    }


    /**
     * Get the vector of travel of the ball.
     * 
     * @return The balls vector.
     */
    public Vector getVector()
    {
        return vector;
    }

    
    /**
     * Get the ball radius.
     * 
     * @return The radius of the all.
     */
    public float getRadius()
    {
        return radius;
    }
	
}
